import { useAIStore } from '@/store/aiStore'

export function useAIFloatingWindow() {
    const aiStore = useAIStore()

    /**
     * 显示AI浮窗
     */
    const showAIWindow = () => {
        aiStore.isWindowVisible = true
        aiStore.isMinimized = false
    }

    /**
     * 隐藏AI浮窗
     */
    const hideAIWindow = () => {
        aiStore.isWindowVisible = false
    }

    /**
     * 切换AI浮窗显示状态
     */
    const toggleAIWindow = () => {
        aiStore.toggleWindow()
    }

    /**
     * 在当前上下文中发送消息
     * @param {string} context - 上下文描述
     * @param {string} question - 问题
     */
    const askAIWithContext = (context, question) => {
        showAIWindow()

        // 等待UI更新
        setTimeout(() => {
            aiStore.addMessage({
                role: 'system',
                content: `当前上下文: ${context}`
            })

            if (question) {
                aiStore.userInput = question
            }
        }, 300)
    }

    return {
        showAIWindow,
        hideAIWindow,
        toggleAIWindow,
        askAIWithContext
    }
}